﻿{% extends "base.html" %}

{% block scripts %}
      <link rel="stylesheet" href="/media/style/jquery.ui.all.css">
    <link rel="stylesheet" href="/media/style/jquery.autocomplete.css">
    <link rel="stylesheet" href="/media/js/chosen/chosen.css">
    <script src="/media/js/chosen/chosen.jquery.js" type="text/javascript"></script>
    <script type="text/javascript" src="/media/js/jquery.autocomplete.min.js"></script>

    <script>
        $(function() {
            $("#id_activities").chosen();
            $("#id_categories").chosen();
            
            $("#id_country").change(function() {
                $("#id_city").val("");
            });

            //автодополнение города.
            $("#id_city").autocomplete("/get_cities/", {
                autoFill: true,
                matchContains: true,
                minChars: 1,
                //mustMatch: true,
                extraParams: {
                    country: function() {
                        return $("#id_country").val();
                    }
                },
                cacheLength: 1,
                selectFirst: true,
                max: 36
            });
        });
    </script>
{% endblock %}

{% block content %}
        		<h1>Редактировать компанию</h1>
				
				<div class="company_edit">					
					<form class="form" action="/edit_company/{{ company.id }}/" method="post" enctype="multipart/form-data">
						{% if form.name.errors %}
                        <dt><p class="error_message">{{ form.name.errors|striptags }}</p></dt>
                        {% endif %}
                        <h2 class="block_header"><label for="id_name">Введите название</label></h2>
						<div class="field_one"><input id="id_name" name="name" class="text_input" type="text" value="{{ company.name }}"></div>
						
						<h2 class="block_header">Фотография</h2>
						<div class="photo_block">
							<p class="description">Вы можете загрузить сюда фотографию. Поддерживаются форматы JPG, PNG и GIF. Файл не должен превышать 5 Mб. Если у Вас возникают проблемы с загрузкой, попробуйте использовать фотографию меньшего размера.</p>
							<div class="block_in">
								<img class="pic"
                                     {% if company.logo %}
                                     src="{{ company.logo.url }}"
                                     {% else %}
                                     src="/media/images/img_no.gif"
                                     {% endif %}
                                     width="70" height="70">
								<span class="file_button">
                                    <span class="button">Загрузить файл</span>
                                    <input class="input" name="logo" id="id_logo" type="file" value=""/>
                                </span>
								<input id="form_company_edit_photo" class="text_input" type="text" readonly/>
							</div>
						</div>
						
						<h2 class="block_header">Данные о компании</h2>
						<dl>
							 <dt>Страна:</dt>
                            <dd><select name="country" id="id_country" class="text_input">
                                {% for country in info.countries %}
                                    <option {% if company.country %}
                                                {% if country.name == company.country.name %} selected="selected"{% endif %}
                                            {% endif %}
                                    >{{ country.name }}</option>

                                {% endfor %}
                            </select></dd>


                            <dt><label for="id_city">Город:</label></dt>
                            <dd><input id="id_city" name="city" class="text_input" type="text" {% if company.city %}value="{{ company.city }}"{% endif %}></dd>

                            <dt><label for="id_fiz_address">Адрес:</label></dt>
								<dd><input id="id_fiz_address" name="fiz_address" class="text_input" type="text" {% if company.fiz_address %}value="{{ company.fiz_address }}"{% endif %}></dd>

                            <dt><label for="id_worktime">Время работы:</label></dt>
								<dd><input id="id_worktime" name="worktime" class="text_input" type="text" {% if company.worktime %}value="{{ company.worktime }}"{% endif %}></dd>

                            <dt><label for="id_phone">Телефон:</label></dt>
								<dd><input id="id_phone" name="phone" class="text_input" type="text" {% if company.phone %}value="{{ company.phone }}"{% endif %}></dd>

                            <dt><label for="id_skype">Skype:</label></dt>
								<dd><input id="id_skype" name="skype" class="text_input" type="text" {% if company.skype %}value="{{ company.skype }}"{% endif %}></dd>

                            <dt><label for="id_icq">icq:</label></dt>
								<dd><input id="id_icq" name="icq" class="text_input" type="text" {% if company.icq %}value="{{ company.icq }}"{% endif %}></dd>

							{% if form.email.errors %}
                                <dt><p class="error_message">{{ form.email.errors|striptags }}</p></dt>
                            {% endif %}
                            <dt><label for="id_email">e-mail:</label></dt>
								<dd><input id="id_email" name="email" class="text_input" type="text" {% if company.email %}value="{{ company.email }}"{% endif %}></dd>

							<dt><label for="id_website">Сайт:</label></dt>
								<dd><input id="id_website" name="website" class="text_input" type="text" {% if company.website %}value="{{ company.website }}"{% endif %}></dd>

                            <dt><label for="id_activities">Виды деятельности:</label></dt>
                            <dd>
                                <select multiple="multiple" id="id_activities" name="activities" data-placeholder="Выберите виды деятельности">
                                {% for activity in info.activities %}
                                    <option value="{{ activity.id }}"{% if activity in company.activities.all %} selected="selected"{% endif %}>{{ activity.name }}</option>
                                {% endfor %}
                                </select>
                            </dd>

                            <dt><label for="id_categories">Категории:</label></dt>
                            <dd>
                                <select multiple="multiple" id="id_categories" name="categories" data-placeholder="Выберите категории">
                                {% for category in info.categories %}
                                    <option value="{{ category.id }}"{% if category in company.categories.all %} selected="selected"{% endif %}>{{ category.name }}</option>
                                {% endfor %}
                                </select>
                            </dd>

                        </dl>

						<h2 class="block_header"><label for="id_description">Описание</label></h2>
						<textarea id="id_description" name="description" cols="80" rows="5">{% if company.description %}{{ company.description }}{% endif %}</textarea>
						
						<!--<h2 class="block_header">Укажите виды деятельности</h2>
						<div class="field_one" style="height: 100px;">
                        </div>
                        <div class="buttons buttons_for_field">
							<input class="button" type="button" value="Удалить">
							<input class="button" type="button" value="Добавить">
						</div>
                        -->


                        <!--
						<div class="for_check for_check_map"><label for="company_edit_include_map"><input id="company_edit_include_map" class="checkbox" type="checkbox">Включить карту</label></div>
						
						<div class="map_wrap">
							<iframe class="" width="232" height="150" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.ru/maps?hl=ru&amp;ie=UTF8&amp;ll=55.72711,49.833984&amp;spn=40.161568,135.263672&amp;z=4&amp;vpsrc=6&amp;output=embed"></iframe>
					
						</div>
						-->
                    <input type="hidden" id="id_owner" name="owner" value="{{ request.user.id }}"
						<div class="buttons"><input class="button" type="submit" value="Сохранить"></div>
					</form>
					
				</div>
			{% endblock %}